package com.springsecuritylearning.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.springsecuritylearning.entity.SysUserEntity;
import com.springsecuritylearning.mapper.SysUserMapper;
import com.springsecuritylearning.service.SysUserService;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.util.Map;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;


@Service("sysUserService")
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUserEntity> implements SysUserService {

    @Override
    public Page<SysUserEntity> queryPage(Integer currentPage, Integer size, Map<String, Object> params) {

        Page<SysUserEntity> page = new Page<>(currentPage, size);

        return this.page(page);
    }

    @Override
    public UserDetails loadUserByUsername(String userName) throws UsernameNotFoundException {

        LambdaQueryWrapper<SysUserEntity> wrapper = Wrappers.<SysUserEntity>lambdaQuery().eq(SysUserEntity::getUsername, userName);

        return this.getOne(wrapper);

    }
}